import React, {Component} from 'react';
import {require} from "../../../netWork";
import './Consult.scss'
import {baseUrl} from "../../../utiles/baseUrl";

const {id} = JSON.parse(localStorage.getItem('hkzf'));
class Consult extends Component {
    state = {groups: []}
    getGroups = () => {
        require({
            url: '/home/news',
            data: id
        }).then(res => {
            res.body.map(res => {
                // console.log(res);
                res.imgSrc = baseUrl + res.imgSrc;
                return 0
            });
            this.setState({groups: res.body})
            // console.log(this.state.groups);
        }).catch(onerror => {
            console.log(onerror);
        })
    };

    componentDidMount() {

        this.getGroups()
    }

    consultView = () => {
        const {groups} = this.state
        return groups.map(item => {
            return <div className='consult' key={item.id}>
                <img src={item.imgSrc} alt=""/>
                <div className='left'>
                    <div className='title'>{item.title}</div>
                    <div className='span'>
                        <span>{item.from}</span>
                        <span>{item.date}</span>
                    </div>
                </div>
            </div>
        })
    };

    render() {
        return (
            <div>
                <h3>最新资讯</h3>
                {this.consultView()}
            </div>
        );
    }
}

export default Consult;
